package org.cboard.dto;

import java.util.Map;

import javax.annotation.Nullable;

import org.cboard.pojo.DashboardBoard;
import org.cboard.pojo.DashboardBoardBase;
import org.cboard.services.role.RolePermission;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Function;
/**
 * Created by yfyuan on 2016/8/23.
 */
public class ViewDashboardBoard extends DashboardBoardBase {

    private Map<String, Object> layout;
	/**
     * 选择的主题
     */
    private String theme;
    private boolean edit;
    private boolean delete;

    public static final Function TO = new Function<DashboardBoard, ViewDashboardBoard>() {
        @Nullable
        @Override
        public ViewDashboardBoard apply(@Nullable DashboardBoard input) {
            return new ViewDashboardBoard(input);
        }
    };

    public ViewDashboardBoard(DashboardBoard board) {
        this.id= board.getId();
        this.userId = board.getUserId();
        this.categoryId = board.getCategoryId();
        this.name = board.getName();
        this.layout = JSONObject.parseObject(board.getLayout());
        this.categoryName = board.getCategoryName();
        this.publishStatus = board.getPublishStatus();
        this.publishUrl = board.getPublishUrl();
		this.edit = RolePermission.isEdit(board.getPermission());
        this.delete = RolePermission.isDelete(board.getPermission());
		
    }

    public boolean isEdit() {
        return edit;
    }

    public void setEdit(boolean edit) {
        this.edit = edit;
    }

    public boolean isDelete() {
        return delete;
    }

    public void setDelete(boolean delete) {
        this.delete = delete;
    }

    
    public Map<String, Object> getLayout() {
        return layout;
    }

    public void setLayout(Map<String, Object> layout) {
        this.layout = layout;
    }

    public String getTheme() {
        return theme;
    }

    public void settheme(String theme) {
        this.theme = theme;
    }
}
